﻿package com.cw.war.ui
{
	import com.cw.war.Model;
	import net.libra.core.interfaces.INotifier;
	import net.libra.core.interfaces.IReceive;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import net.libra.ui.EasyButton;



	/**
	 * 二级子窗口
	 * @author elvisjiang
	 */
	public class Box extends AbstractPopup
	{
//		protected var model : Model;
		// -------------------------------------------------------------------------------------
		// ui实例
		protected var closeBtn : EasyButton;
		protected var helpBtn : EasyButton;
		protected var skin : MovieClip;
		/**
		 * 是否为层级窗口
		 * 默认是层级窗口
		 * @param mulitLayer
		 * 
		 */
		public function Box (isMulitLayer : Boolean = true )
		{
			super(isMulitLayer);
			
			this.mouseChildren = this.mouseEnabled = true;
			//
//			this.model = Model.getInstance() ();
//			Sender.register ( this );
			//
			this.setModal ( false );
			// 创建窗口背景
			this.skin = this.getFrameAssets ();
			this.addChild ( this.skin );
			if(this.skin.closeBtn)
			{
				this.closeBtn = EasyButton.createEasyButton ( this.skin.closeBtn );
				this.closeBtn.addEventListener ( MouseEvent.CLICK , this.doClose );
			}
			if(this.skin.helpBtn)
			{
				this.helpBtn = EasyButton.createEasyButton ( this.skin.helpBtn );
				this.helpBtn.addEventListener ( MouseEvent.CLICK , showHelp );
			}
			
		}
		
		protected function doClose ( e : Event = null ) : void
		{
			this.close ();
		}
		
		override public function destroy () : void
		{
			if(this.closeBtn){
				this.closeBtn.removeEventListener ( MouseEvent.CLICK , this.doClose );
				this.removeChild ( this.skin );
				this.skin  = null;
			}
			super.destroy ();
		}
		
		protected function showHelp ( e : Event = null ) : void
		{
		}

		protected function getFrameAssets () : MovieClip
		{
			return new Lib_FrameMC ();
		}

		override public function get width () : Number
		{
			return this.skin.width;
		}

		override public function get height () : Number
		{
			return this.skin.height;
		}
	}
}
